package com.sgcc.operate.controller;

import com.sgcc.common.core.utils.poi.ExcelUtil;
import com.sgcc.common.core.web.controller.BaseController;
import com.sgcc.common.core.web.domain.AjaxResult;
import com.sgcc.common.core.web.page.TableDataInfo;
import com.sgcc.common.datascope.annotation.DataScope;
import com.sgcc.common.log.annotation.Log;
import com.sgcc.common.log.enums.BusinessType;
import com.sgcc.common.security.annotation.PreAuthorize;
import com.sgcc.operate.domain.OMsgMng;
import com.sgcc.operate.service.IOMsgMngService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 消息模板管理Controller
 * 
 * @author sgcc
 * @date 2021-03-26
 */
@RestController
@RequestMapping("/msgmng")
public class OMsgMngController extends BaseController
{


    @Autowired
    private IOMsgMngService oMsgMngService;

    /**
     * 查询消息模板管理列表
     */
    //@PreAuthorize(hasPermi = "operate:msgmng:list")
    @GetMapping("/list")
    @DataScope(deptAlias = "o2")
    public TableDataInfo list(OMsgMng oMsgMng)
    {
        startPage();
        List<OMsgMng> list = oMsgMngService.selectOMsgMngList(oMsgMng);
        return getDataTable(list);
    }

    /**
     * 导出消息模板管理列表
     */
    //@PreAuthorize(hasPermi = "operate:msgmng:export")
    @Log(title = "消息模板管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OMsgMng oMsgMng) throws IOException
    {
        List<OMsgMng> list = oMsgMngService.selectOMsgMngList(oMsgMng);
        ExcelUtil<OMsgMng> util = new ExcelUtil<OMsgMng>(OMsgMng.class);
        util.exportExcel(response, list, "msgmng");
    }

    /**
     * 获取消息模板管理详细信息
     */
    //@PreAuthorize(hasPermi = "operate:msgmng:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(oMsgMngService.selectOMsgMngById(id));
    }

    /**
     * 新增消息模板管理
     */
    //@PreAuthorize(hasPermi = "operate:msgmng:add")
    @Log(title = "消息模板管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OMsgMng oMsgMng)
    {
        return toAjax(oMsgMngService.insertOMsgMng(oMsgMng));
    }

    /**
     * 修改消息模板管理
     */
    //@PreAuthorize(hasPermi = "operate:msgmng:edit")
    @Log(title = "消息模板管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OMsgMng oMsgMng)
    {
        return toAjax(oMsgMngService.updateOMsgMng(oMsgMng));
    }

    /**
     * 删除消息模板管理
     */
    //@PreAuthorize(hasPermi = "operate:msgmng:remove")
    @Log(title = "消息模板管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(oMsgMngService.deleteOMsgMngByIds(ids));
    }

    /**
     * 查询群组管理列表
     */
    //@PreAuthorize(hasPermi = "operate:groupmng:list")
    @GetMapping("/optionselect")
    public AjaxResult optionselect(OMsgMng oMsgMng)
    {
        return AjaxResult.success(oMsgMngService.selectOMsgMngList(oMsgMng));
    }

}
